//
//  MJRefreshGifHeader+DYY.m
//  DYPlayNews
//
//  Created by SH_iOS on 2017/6/3.
//  Copyright © 2017年 https://github.com/DefaultYuan . All rights reserved.
//

#import "MJRefreshGifHeader+DYY.h"

@implementation MJRefreshGifHeader (DYY)

+ (instancetype)DYHeaderWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock
{
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:refreshingBlock];
//    
//    NSArray *idleImages = [self imagesForRefresh];
//    NSArray *refreshingImages = [self imagesForRefresh];
//    
//    [header setImages:idleImages forState:MJRefreshStateIdle]; // 设置下拉过程的动画图片
//    [header setImages:refreshingImages forState:MJRefreshStatePulling]; // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
//    [header setImages:refreshingImages forState:MJRefreshStateRefreshing]; // 设置正在刷新状态的动画图片
    header.lastUpdatedTimeLabel.hidden = YES; // 隐藏时间
    header.stateLabel.hidden = YES; // 隐藏状态
    UIView *top = [[UIView alloc]init];
    top.backgroundColor = [UIColor blueColor];
    [header addSubview:top];
    UIImageView *topView = [[UIImageView alloc]init];
    topView.image = [UIImage imageNamed:@"navImage"];
    [header addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(header.mas_left);
        make.bottom.equalTo(header.mas_top).offset(54);
        make.height.mas_equalTo(__I6Height(1000));
        make.width.mas_equalTo(KScreenWidth);
        
    }];

    
    return header;
}


- (void)prepare
{
    [super prepare];
    
    
    // 设置即将刷新状态的动画图片（一松开就会刷新的状态）
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 1; i<=48; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"shrefresh%zd_03", i]];
        [refreshingImages addObject:image];
    }
    [self setImages:refreshingImages forState:MJRefreshStatePulling];
    
    // 设置正在刷新状态的动画图片
    [self setImages:refreshingImages forState:MJRefreshStateRefreshing];
}

//
//+ (NSArray *) imagesForRefresh
//{
//    static NSArray *images = nil;
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        NSMutableArray *refreshImages = [NSMutableArray array];
//        for (NSUInteger i = 1; i< 24; i++) {
//            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"shrefresh%zd_03", i]];
//            [refreshImages addObject:image];
//        }
//        images = [refreshImages copy];
//    });
//    return images;
//}

@end
